<%@ page import="service.ProductService" %>
<%@ page import="service.impl.ProductServiceImpl" %>
<%@ page import="java.util.List" %>
<%@ page import="entity.Product" %><%--
  Created by IntelliJ IDEA.
  User: 楠春初下
  Date: 2022-08-10
  Time: 14:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
    <title>Title</title>
    <style>
        table tr td {
            border: 1px solid #ccc;
        }
    </style>
    <script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
<table>
    <tr>
        <td>商品编号</td>
        <td>商品名称</td>
        <td>商品价格</td>
        <td>商品描述</td>
        <td>商品状态</td>
        <td>操作</td>
    </tr>

    <c:forEach items="${list}" var="product">
        <tr>
            <td>${product.id}</td>
            <td>${product.product_name}</td>
            <td>${product.product_price}</td>
            <td>${product.product_desc}</td>
            <c:if test="${product.flag==0}">
                <td>下架</td>
            </c:if>
            <c:if test="${product.flag==1}">
                <td>上架</td>
            </c:if>
            <td><a href="#" onclick="Delete(${product.id})">删除</a>
                <a href="${pageContext.request.contextPath}/ProductSelect_upServlet?id=${product.id}">修改</a></td>
        </tr>
    </c:forEach>
</table>
<a href="product/product_inset.jsp">新增</a>
<script>
    function Delete(id){
        var sf = confirm("确定要删除吗？");
        if (sf == true){
            $.get("${pageContext.request.contextPath}/ProductDeleteServlet","id="+id,function (data){
                if (data>0){
                    alert("删除成功")
                    location.href="${pageContext.request.contextPath}/ProductSelectServlet"
                }
            })
        }
    }
</script>
</body>
</html>
